<?php

namespace App\Http\Controllers\Activity;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ActivityStatusChangeController extends Controller

{

    public function index(){

        $all = $this->all;
        $date = date('Y-m-d H:i:s');

        try{
            //活动已开始或结束，不允许修改
            $result = DB::table('lottery_activity')
                ->where('act_id',$all['act_id'])
                ->where('start_time','>',$date)
                ->update(['is_stop'=>$all['is_stop']]);
            if($result === 0){
                return $this->setReturnJson(-1,'活动已开始或结束，不允许修改状态');
            }
            return $this->setReturnJson(0,'状态修改完成');
        }catch (\Exception $e){
            Log::error(ActivityStatusChangeController::class,['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'处理异常，请刷新页面重试');
        }

    }

}
